﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MoveToDoList
{
	class ProjectToDoListsAdapter : IProjectToDoLists
	{
		private ComboBox _projects;
		private ListBox _toDos;

		public static ProjectToDoListsAdapter GetInstance(ComboBox projects, ListBox toDos)
		{
			return new ProjectToDoListsAdapter(projects, toDos);
		}
		private ProjectToDoListsAdapter(ComboBox projects, ListBox toDos)
		{
			_projects = projects;
			_toDos = toDos;
		}

		#region Implementation of IProjectToDoLists

		public int ProjectSelectedIndex
		{
			get { return _projects.SelectedIndex; }
			set { _projects.SelectedIndex = value; }
		}

		public void AddProject(string name)
		{
			_projects.Items.Add(name);
		}

		public void ClearToDoLists()
		{
			_toDos.Items.Clear();
		}

		public void ToDoListsAddItem(string item)
		{
			_toDos.Items.Add(item);
		}

		public int SelectedList
		{
			get { return _toDos.SelectedIndex; }
		}

		public int[] SelectedLists
		{
			get
			{
				int[] result = new int[_toDos.SelectedIndices.Count];
				_toDos.SelectedIndices.CopyTo(result, 0);
				return result;
			}
		}

		#endregion
	}
}
